package com.example.zhyq.repair

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.base.entity.RepairBeanItem
import com.example.base.mvvm.BaseActivity
import com.example.zhyq.R
import com.example.zhyq.databinding.ActivityRepairDetailBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/RepairDetailActivity")
@AndroidEntryPoint
class RepairDetailActivity : BaseActivity<ActivityRepairDetailBinding,RepairViewModel>() {

    @Autowired
    lateinit var rid : String
    lateinit var bean: RepairBeanItem

    override fun initView() {
        ARouter.getInstance().inject(this)
        vm.getRepairById(rid.toInt())

        binding.headRepDetail.headerTitle.text = "编辑维修"
        binding.headRepDetail.headerBack.setOnClickListener {
            finish()
        }
        binding.headRepDetail.apply {
            headerAdd.setImageResource(R.drawable.baseline_add_24)

        }

        //点击处理
        binding.repDetailOk.setOnClickListener {
            approve("处理中")
        }

        //点击完成
        binding.repDetailRefause.setOnClickListener {
            approve("已完成")
        }
    }

    fun approve(status:String) {
        bean.processingStatus = status
        vm.updateRepair(rid.toInt(),bean)
    }

    override fun initData() {
        vm.getRepairByIdSuc.observe(this) {
            binding.bean = it
            bean=it

            if (it.processingStatus=="处理中"){
                binding.repDetailProCircle2.setBackgroundResource(R.drawable.shape_solid_darkgreen)
                binding.repDetailGroup.visibility = View.VISIBLE
            }else if (it.processingStatus=="已完成"){
                binding.repDetailProCircle2.setBackgroundResource(R.drawable.shape_solid_darkgreen)
                binding.repDetailProCircle3.setBackgroundResource(R.drawable.shape_solid_darkgreen)
            }else{
                binding.repDetailGroup.visibility = View.VISIBLE
            }
        }

        vm.updateRepairSuc.observe(this) {
            ToastUtils.showLong("操作完成")
            finish()
        }
    }
}